import $ from "jquery";
$.fn.numberRock = function(options) {
    var defaults = {
        lastNumber: 100,
        duration: 2000,
        easing: "swing" //swing(默认 : 缓冲 : 慢快慢)  linear(匀速的)
    };
    var opts = $.extend({}, defaults, options);

    $(this).animate({
        num: "numberRock"
            // width : 300,
            // height : 300,
    }, {
        duration: opts.duration,
        easing: opts.easing,
        complete: function() {
            console.log("success");
        },
        step: function(a, b) {
            //可以检测我们定时器的每一次变化
            //console.log(a);
            //console.log(b.pos);   //运动过程中的比例值(0~1)
            $(this).html(parseInt(b.pos * opts.lastNumber));
        }
    });
};

export var Stare = function() {
    var cols = [
        "#f5d76e",
        "#f7ca18",
        "#f4d03f",
        "#ececec",
        "#ecf0f1",
        "#a2ded0"
    ];
    var stars = 50;

    for (var i = 0; i <= stars; i++) {
        var size = Math.random() * 3;
        var color = cols[parseInt(Math.random() * 4)];

        $("#starsBox").prepend(
            '<span style=" width: ' +
            size +
            "px; height: " +
            size +
            "px; top: " +
            Math.random() * 50 +
            "%; left: " +
            Math.random() * 50 +
            "%; background: " +
            color +
            "; box-shadow: 0 0 " +
            Math.random() * 10 +
            "px" +
            color +
            '"></span>'
        );
    }

    setTimeout(function() {
        $("#starsBox span").each(function() {
            $(this)
                .css("top", Math.random() * 100 + "%")
                .css("left", Math.random() * 100 + "%");
        });
    }, 1);

    setInterval(function() {
        $("#starsBox span").each(function() {
            $(this)
                .css("top", Math.random() * 100 + "%")
                .css("left", Math.random() * 100 + "%");
        });
    }, 100000);
}